Repository navigation
Conversation
A naked T extends never splits multi-label metrics into a union of one-key objects, so reading labels back from get() keeps only one key. Fixes prometheus#861 Signed-off-by: Christopher Pruijsen <christopher.pruijsen@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Tuple-wrap both sides of the
LabelValuescheck ([T] extends [NoLabelNameType]) so a multi-labelget()keeps every declared key.LabelValues<T>was a naked distributive conditional (T extends never). For a metric with two label names,LabelValuesbecame a union of one-key objects, soconst { values } = await counter.get(); values[0].labels.afailed to compile (TS2339) even though both keys were declared. The no-labelnevercase resolves toPartial<Record<string, never>>(the empty-record type #655 intended; the naked form yieldedneverby distributing over the empty union).test/typescript.tsreads.methodand.statusfrom a two-label Counter and Gaugeget(). That access failstscon the old type.Fixes #861.
Decision
Tuple-wrap both sides of the
LabelValuescheck rather than revert toPartial<Record<T, string | number>>(prom-client 15.1.3). The tuple wrap is the form in the issue, and it keeps the no-label empty-record type from #655. Reverting would drop that branch.Happy to switch if you would rather revert the alias, drop the changelog line, or also cover Histogram/Summary
get()reads (same alias).Test plan
npm run compile-typescriptpasses with the wrap.index.d.tsline; the newget()label reads failtscwithTS2339on the one-key union.tscis clean again.npm run lintandnpm run check-prettierpass.